import { createRouter, createWebHistory } from 'vue-router';
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/index',
    },
    {
      path: '/index',
      name: 'index',
      component: () => import('@/views/vHome.vue'),
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login.vue'),
    },
    {
      path: '/login/callback',
      name: 'callback',
      component: () => import('@/components/callback/callback.vue'),
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/register.vue'),
    },
    {
      path: '/healthEncyclopedia',
      name: 'healthEncyclopedia',
      component: () => import('@/views/healthEncyclopedia.vue'),
    },
    {
      path: '/recommendFollow',
      name: 'recommendFollow',
      component: () => import('@/views/recommendFollow.vue'),
    },
    {
      path: '/search',
      name: 'search',
      component: () => import('@/views/search.vue'),
    },
    {
      path: '/articleDetail/:keyword',
      name: 'articleDetail',
      component: () => import('@/views/articleDetail.vue'),
    },
    {
      path: '/doctorDetail/:keyword',
      name: 'doctorDetail',
      component: () => import('@/views/doctorDetail.vue'),
    },
    {
      path: '/topicDetail/:keyword',
      name: 'topicDetail',
      component: () => import('@/views/topicDetail.vue'),
    },
    // 首页找医生
    {
      path: '/findDoctor',
      name: 'findDoctor',
      component: () => import('@/views/findDoctor.vue'),
    },
    // 首页极速问诊
    {
      path: '/fastConsult',
      name: 'fastConsult',
      component: () => import('@/views/fastConsult.vue'),
    },
    // 首页开药问诊
    {
      path: '/medicineConsult',
      name: 'medicineConsult',
      component: () => import('@/views/medicineConsult.vue'),
    },
    {
      path: '/doctorList',
      name: 'doctorList',
      component: () => import('@/views/doctorList.vue'),
    },

    // 我的
    {
      path: '/my',
      name: 'my',
      component: () => import('@/views/my.vue'),
    },
    {
      path: '/describeIllness',
      name: 'describeIllness',
      component: () => import('@/views/describeIllness.vue'),
    },
    {
      path: '/choosePatient',
      name: 'choosePatient',
      component: () => import('@/views/choosePatient.vue'),
    },
    // 修改昵称
    {
      path: '/editName/:keyword',
      name: 'editName',
      component: () => import('@/views/editName.vue'),
    },
    {
      path: '/consultPay',
      name: 'consultPay',
      component: () => import('@/views/consultPay.vue'),
    },
    // 我的收藏
    {
      path: '/myCollection',
      name: 'myCollection',
      component: () => import('@/views/myCollection.vue'),
    },
    // 选择科室
    {
      path: '/chooseDep',
      name: 'chooseDep',
      component: () => import('@/views/chooseDep.vue'),
    },
    // 药品订单
    {
      path: '/medicineOrder',
      name: 'medicineOrder',
      component: () => import('@/views/medicineOrder.vue'),
    },
    // 消息通知
    {
      path: '/message',
      name: 'message',
      component: () => import('@/views/message.vue'),
    },
    {
      path: '/chatRoom/:keyword',
      name: 'chatRoom',
      component: () => import('@/views/chatRoom.vue'),
    },
    // 我的处方
    {
      path: '/prescriptionList',
      name: 'prescriptionList',
      component: () => import('@/views/prescriptionList.vue'),
    },
    // 疾病查询
    {
      path: '/illnessSearch',
      name: 'illnessSearch',
      component: () => import('@/views/illnessSearch.vue'),
    },
    // 疾病查询
    {
      path: '/illnessDetail',
      name: 'illnessDetail',
      component: () => import('@/views/illnessDetail.vue'),
    },
    // 地址
    {
      path: '/addressManage',
      name: 'addressManage',
      component: () => import('@/views/addressManage.vue'),
    },
  ],
});

import { useIndexStore } from '@/store/index';

router.beforeEach((to, from, next) => {
  const store = useIndexStore();
  store.$state.loading = true;
  next();
});

router.afterEach(() => {
  const store = useIndexStore();
  store.$state.loading = false;
});
export default router;
